package com.example.springbott.wx_controller;

import com.example.springbott.bean.BaseRespVo;
import com.example.springbott.bean.MarketOrder;
import com.example.springbott.bean.MarketOrderExample;
import com.example.springbott.mapper.MarketOrderMapper;
import com.example.springbott.service.AdminIssueService;
import com.example.springbott.wx_bean_heheer.OrderDetailVODate;
import com.example.springbott.wx_bean_heheer.OrderListBO;
import com.example.springbott.wx_bean_heheer.OrderListVODate;
import com.example.springbott.wx_bean_heheer.OrderSubmitBO;
import com.example.springbott.wx_bean_heheer.order.OrderCommentBO;
import com.example.springbott.wx_bean_heheer.order.OrderDetailVO;
import com.example.springbott.wx_bean_heheer.order.OrderGoodsVO;
import com.example.springbott.wx_service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author 1784549954@qq.com
 * @since 2022/11/22 10:52
 */
@RestController
@RequestMapping("wx/order")
public class WXOrderController {
    @Autowired
    OrderService orderService;

    @Autowired
    MarketOrderMapper marketOrderMapper;


    /**
     * 显示订单信息
     *
     * @param orderListBO
     * @return com.example.springbott.bean.BaseRespVo
     * @author heheer
     * @since 2022/11/22 20:13
     */
    @RequestMapping("list")
    public BaseRespVo orderList(OrderListBO orderListBO) {
        OrderListVODate orderListVODate = orderService.orderList(orderListBO);
        return BaseRespVo.ok(orderListVODate);
    }

    /**
     * 订单详情
     *
     * @param orderId
     * @return com.example.springbott.bean.BaseRespVo
     * @author heheer
     * @since 2022/11/22 21:50
     */
    @RequestMapping("detail")
    public BaseRespVo orderDatail(String orderId) {
        OrderDetailVO orderDetail = orderService.OrderDetail(orderId);
        return BaseRespVo.ok(orderDetail);
    }

    /**
     * 删除订单
     *
     * @param map
     * @return
     */
    @RequestMapping("delete")
    public BaseRespVo orderDelete(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        orderService.orderDelete(orderId);
        return BaseRespVo.ok(null);
    }


    /**
     * 取消订单
     *
     * @param map
     * @return com.example.springbott.bean.BaseRespVo
     * @author heheer
     * @since 2022/11/23 10:39
     */
    @RequestMapping("cancel")
    public BaseRespVo orderCancel(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        orderService.orderCancel(orderId);
        return BaseRespVo.ok(null);

    }


    /**
     * 确认收货
     *
     * @param map
     * @return com.example.springbott.bean.BaseRespVo
     * @author heheer
     * @since 2022/11/23 11:36
     */
    @RequestMapping("confirm")
    public BaseRespVo orderConfirm(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        orderService.orderConfirm(orderId);
        return BaseRespVo.ok(null);
    }

    /**
     * 申请退款
     *
     * @param map
     * @return com.example.springbott.bean.BaseRespVo
     * @author heheer
     * @since 2022/11/23 11:37
     */
    @RequestMapping("refund")
    public BaseRespVo orderRefund(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        orderService.orderRefund(orderId);
        return BaseRespVo.ok(null);

    }


    /**
     * 评价回显信息
     *
     * @return com.example.springbott.bean.BaseRespVo
     * @author heheer
     * @since 2022/11/23 14:54
     */
    @RequestMapping("goods")
    public BaseRespVo orderGoods(String orderId, String goodsId) {

        OrderGoodsVO orderGoodsVO = orderService.orderGoods(orderId, goodsId);
        return BaseRespVo.ok(orderGoodsVO);
    }


    /**
     * 商品评论
     *
     * @param orderComment
     * @return com.example.springbott.bean.BaseRespVo
     * @author heheer
     * @since 2022/11/23 19:09
     */
    @RequestMapping("comment")
    public BaseRespVo orderComment(@RequestBody OrderCommentBO orderComment) {
        orderService.orderComment(orderComment);
        return BaseRespVo.ok(null);
    }

    /**
     * 下单生成订单表和订单商品表
     *
     * @param orderSubmitBO
     * @return com.example.springbott.bean.BaseRespVo
     * @author heheer
     * @since 2022/11/23 21:08
     */
    @RequestMapping("submit")
    public BaseRespVo orderSubmit(@RequestBody OrderSubmitBO orderSubmitBO) {

        return BaseRespVo.ok(orderService.orderSubmit(orderSubmitBO));
    }

    @RequestMapping("prepay")
    public BaseRespVo orderPrepay(@RequestBody Map map){
        String orderId =  map.get("orderId").toString();
        MarketOrder marketOrder = new MarketOrder();
        marketOrder.setOrderStatus((short) 201);
        MarketOrderExample marketOrderExample = new MarketOrderExample();
        MarketOrderExample.Criteria criteria = marketOrderExample.createCriteria();
        criteria.andIdEqualTo(Integer.parseInt(orderId));
        marketOrderMapper.updateByExampleSelective(marketOrder,marketOrderExample);
        return BaseRespVo.ok();
    }
}
